package com.nage.components.movement;

/**
 * Represents a 2D Vector which is used in physics calculations. This can be a 
 * point (position of object), or a vector (velocity, acceleration etc).
 * @author lukeo05
 *
 */
public class Vector2D {
	
	public float x;
	public float y;
	
	public Vector2D() {
		x = 0;
		y = 0;
	}
	public Vector2D(float x, float y) {
		this.x = x;
		this.y = y;
	}

	/**
	 * Adds a vector to itself, updating its member variables.
	 * 
	 * @param f	The vector to add
	 */
	public void add(Vector2D f) {
		x += f.x;
		y += f.y;
	}
	
	/**
	 * Adds a vector (specified by its component parts) to itself, updating its member variables
	 * @param x		x component to add
	 * @param y		y component to add
	 */
	public void add(float x, float y) {
		this.x += x;
		this.y += y;
	}

	/**
	 * Divide itself by a scalar value and return the result.
	 * 
	 * @param mass	Scalar value to divide vector by
	 * @return		New vector representing this / mass
	 */
	public Vector2D divide(float mass) {
		return new Vector2D(x/mass, y/mass);
	}
	
	@Override
	public String toString() {
		return "x = "+x+" y = "+y;
	}

	public Vector2D multiply(float f) {
		return new Vector2D(x*f, y*f);
	}

	public void reset() {
		x = 0;
		y = 0;
	}

	public void set(float x, float y) {
		this.x = x;
		this.y = y;
	}
	/**
	 * Minuses a vector from itself and returns the result. Does not update state.
	 * @param vel
	 * @return
	 */
	public Vector2D minus(Vector2D v) {
		return new Vector2D(x - v.x, y - v.y);
	}
	
	/**
	 * Performs the dot product of the two parameters and returns a new float
	 * with the result
	 * 
	 * @param a
	 * @param b
	 * @return		float with result
	 */
	public static float dot(Vector2D a, Vector2D b) {
		return a.x*b.x + a.y*b.y;
	}
}
